package com.wind.sql;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import com.wind.bean.TotalTraffs;

public class DBInitTables {
	// private String TAG = "sptest";

	private String CreateTable = "CREATE TABLE IF NOT EXISTS ";
	private String CreateID = "(_id INTEGER PRIMARY KEY";
	private String CreateParamTotal = ",region INTEGER,number INTEGER,sqrt TEXT,mark TEXT,other1 TEXT,other2 TEXT,latitude DOUBLE, longitude DOUBLE,type INTEGER)";

	private String InsertTable = "INSERT INTO ";
	private String InsertValues = " VALUES ('";
	private String InsertSplite = "','";
	private String InsertEnd = "')";
	private String InsertTotalParam = " (latitude,longitude,type) ";

	private SimpleDateFormat dateFormate;
	private SimpleDateFormat timeFormate;

	public DBInitTables() {
		dateFormate = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
		timeFormate = new SimpleDateFormat("HH:mm:ss", Locale.CHINA);
	}

	public List<String> createTotalTableSqls() {
		List<String> sqls = new ArrayList<String>();
		sqls.add(createTotalTable());
		// sqls.add(initTotalTable(0));
		// sqls.add(initTotalTable(1));
		return sqls;
	}

	// CREATE TABLE IF NOT EXISTS t4 (_id INTEGER PRIMARY KEY,date
	// datetime,upload INTEGER,download INTEGER,uid INTEGER,type
	// varchar(15),other varchar(15))
	/**
	 * 初始化总流量统计的表格
	 * 
	 * @param flag
	 *            用于标识操作的表 mobile,flag=0;wifi,flag=1;
	 * @return
	 */
	private String createTotalTable() {
		StringBuilder sb = new StringBuilder();
		sb.append(CreateTable);
		sb.append(DBManager.AREA_TABLE);
		sb.append(CreateID);
		sb.append(CreateParamTotal);
		return sb.toString();
	}

	/**
	 * 初始化总流量统计的表格内容
	 * 
	 * @param flag
	 *            用于标识操作的表mobile,flag=0;wifi,flag=1;
	 * @return
	 */
	private String initTotalTable(int flag) {
		// INSERT INTO t4 (date,time,upload,download,uid,type) VALUES
		// ('date','time','upload','download','uid','type')
		long time = System.currentTimeMillis();
		StringBuilder sb = new StringBuilder();
		sb.append(InsertTable);
		if (flag == 0) {
			sb.append(DBManager.MOBILE_TABLE);
		} else
			sb.append(DBManager.WIFI_TABLE);
		sb.append(InsertTotalParam);
		sb.append(InsertValues);
		sb.append(dateFormate.format(time));
		sb.append(InsertSplite);
		sb.append(timeFormate.format(time));
		sb.append(InsertSplite);
		sb.append(InsertSplite);
		// type=0标识标识即时读取的流量值
		sb.append(0);
		sb.append(InsertEnd);
		return sb.toString();
	}

}
